package com.sinosoft.cnmuseum.dao;


import java.util.HashMap;
import java.util.List;

import com.sinosoft.cnmuseum.entity.MbMusicGcxx;
import com.sinosoft.cnmuseum.entity.MbMusicGcxx;
import com.sinosoft.commontools.record.Record;
import com.sinosoft.dbtools.operate.single.DBSingleTableActorMgr;


public class MbMusicGcxxDao extends BaseDao{

	public MbMusicGcxxDao() {
		this.actor = DBSingleTableActorMgr.getDBSingleTableActor("Mb_music_gcxx");
	}
	
	public String getLastCjr(String mainflowid){
		String sql = "select * from Mb_music_gcxx where flowid like '%"+mainflowid+"' order by id desc";
		List<Record> list = this.getBySql(sql);
		if(list!=null){
			Record r = list.get(0);
			String lastcjr = r.getStrValue(MbMusicGcxx.ASSIGNEEUSER);
			return lastcjr;
		}
		return "";
	}
	
	public Record getByFlowid(String mainflowid){
		String sql = "select * from Mb_music_gcxx where flowid = '"+mainflowid+"' order by id desc";
		List<Record> list = this.getBySql(sql);
		if(list!=null){
			Record r = list.get(0);
			return r;
		}
		return null;
	}
	
	
	/**      
	 * getIsNewData 按藏品编号查询最新记录 
	 * @author wangli
	 * @param collection_code
	 * @return          
	*/
	public Record getIsNewData(String collection_code){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(MbMusicGcxx.COLLECTIONCODE, collection_code);
		map.put(MbMusicGcxx.ISNEW, 1);
		List<Record> list = this.getListByProperty(map);
		if(list!=null){
			Record r = list.get(0);
			return r;
		}
		return null;
	}
	
	public List<Record> getIsNewDatas(String collection_code){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(MbMusicGcxx.COLLECTIONCODE, collection_code);
		map.put(MbMusicGcxx.ISNEW, 1);
		List<Record> list = this.getListByProperty(map);
		if(list!=null){
			return list;
		}
		return null;
	}
	
	public String getLastFlowstep(String mainflowid){
		String sql = "select * from Mb_music_gcxx where flowid like '%\\_"+mainflowid+"\\_%' order by id desc";
		List<Record> list = this.getBySql(sql);
		if(list!=null&&list.size()>0){
			Record r = list.get(0);
			String laststep = r.getStrValue(MbMusicGcxx.FLOWSTEP);
			return laststep;
		}
		return "";
	}
	
	public List<Record> getAllFlow(String mainflowid){
		String sql = "select * from Mb_music_gcxx where flowid like '%\\_"+mainflowid+"\\_%' order by id desc";
		List<Record> list = this.getBySql(sql);
		if(list!=null&&list.size()>0){
			return list;
		}
		return null;
	}
	
	public boolean getFlowingData(String collection_code){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(MbMusicGcxx.COLLECTIONCODE, collection_code);
		map.put(MbMusicGcxx.ISRUNNING, 1);
		List<Record> list = this.getListByProperty(map);
		if(list!=null&&list.size()>0){
			Record r = list.get(0);
			return true;
		}
		return false;
	}

}
